package com.vidyu.datalayer.dataaccesscomponents.impl;

import com.vidyu.businesslayer.businessentities.Contract;
import com.vidyu.businesslayer.businessentities.Skill;
import com.vidyu.datalayer.dataaccesscomponents.ContractDao;
import com.vidyu.datalayer.dataaccesscomponents.SkillDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: eyalsa
 * Date: 28/02/12
 * Time: 14:38
 * Implementation Dao object for ContractorDao
 */

@SuppressWarnings({"unchecked", "UnusedDeclaration"})
@Repository("skillDao")
public class SkillDaoImpl extends BaseDaoImpl implements SkillDao {

    @Autowired
    private HibernateTemplate template;

    @Override
    @Transactional(readOnly = false, propagation = Propagation.NESTED)
    public long save(Skill skill){
        return ((Long) template.save(skill));
    }

    @Override
    public void update(Skill skill){
        template.update(skill);
    }

    @Override
    @Transactional(readOnly = false, propagation = Propagation.NESTED)
    public void delete(Skill skill) {
        template.delete(skill);
    }

    @Override
    @Transactional(readOnly = false, propagation = Propagation.NESTED)
    public Skill findById(long id) {
        return template.get(Skill.class, id);
    }

    @Override
    public Skill getSkillDesc(String skillTitle)
    {
        List<Skill> skills = this.findByNamedQuery("getSkillDesc", skillTitle);
        if (skills.isEmpty()) {
            return null;
        }
        return skills.get(0);
    }
}
